package com.itheima02.day05;

/**
 * @author 刘全
 * @date 2021/7/21
 */
//递归
public class DiGui {
    public static void main(String[] args) {
        int result = sum(100);
        System.out.println(result);
        int r = sum2(20);
        System.out.println(r);
    }
//有个人养了一对兔子,从第二个月开始,每个月都生一对兔子,问到20个月兔子总共有多少对
    private static int sum2(int month) {
        if (month == 1 || month == 2) {
            return 1;
        } else {
            return sum2(month - 1) + sum2(month - 2);
        }
    }

    private static int sum(int i) {
        if (i == 1) {
            return 1;
        } else {
            return i + sum(i - 1);
        }
    }
}
